package cn.lanqiao.demo.controller;

import cn.lanqiao.demo.entity.User;
import cn.lanqiao.demo.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserService userService;

    @RequestMapping("/login")
    public List login(String username, String password, Integer user_type, HttpServletResponse response) throws IOException {
        return userService.login(username, password, user_type);
    }

    @RequestMapping("/adduser")
    public String adduser(String username, String password, Integer user_type,HttpServletResponse response) throws IOException {
        return userService.addUser(username,password,user_type);
    }

    //根据用户名密码修改用户密码
    @GetMapping("/update")
    public String updateUserPassword(String username,String password,String newPwd){
        Integer update = userService.updateUserPassword(username,password,newPwd);
        if (update != 0){//修改成功，向浏览器打印ok
            return "ok";
        }else {
            return "no";//修改失败，向浏览器打印no
        }
    }
}